import React from "react";
import { useRoutes, Outlet, Navigate } from "react-router-dom";
import { lazyLoading } from "@/utils";
import AuthComponent from "@/components/AuthComponent";
import Index from "@/pages/Index";
import { DatabaseOutlined, HomeOutlined, MedicineBoxOutlined, SmileOutlined } from "@ant-design/icons";

const routes = [
    {
        path: "/",
        element: (
            <AuthComponent>
                <Index />
            </AuthComponent>
        ), children: [
            {
                // 主页
                path: "/",
                label: "主页",
                icon: <HomeOutlined />,
                element: lazyLoading("Home")
            },
            {
                // 数据管理
                path: "/cmn",
                label: "数据管理",
                icon: <DatabaseOutlined />,
                element: <Outlet />,
                children: [
                    {
                        path: "/cmn",
                        label: "数据管理",
                        isHide: true,// 是否隐藏
                        element: <Navigate to={"/cmn/dict"} />
                    },
                    {
                        // 数据字典
                        path: "/cmn/dict",
                        label: "数据字典",
                        element: lazyLoading("cmn/dict")
                    }
                ]
            }, {
                // 医院管理
                path: "/hospital",
                label: "医院管理",
                icon: <MedicineBoxOutlined />,
                element: <Outlet />,
                children: [
                    {
                        path: "/hospital",
                        // label:"医院管理",
                        element: <Navigate to={"/hospital/hospitalSet"} />,
                        isHide: true
                    }, {
                        path: "/hospital/hospitalSet",
                        element: lazyLoading("hospital/hospitalSet"),
                        label: "医院设置"
                    }, {
                        path: "/hospital/hospitalList",
                        element: lazyLoading("hospital/hospitalList"),
                        label: "医院列表"
                    }, {
                        path: "/hospital/show/:id",
                        isHide: true,
                        element: lazyLoading("hospital/show"),
                        label: "医院详情"
                    }, {
                        path: "/hospital/department/:hoscode",
                        isHide: true,
                        element: lazyLoading("hospital/department"),
                        label: "医院排班"
                    }
                ]
            }, {
                // 商品管理
                path: "/product",
                label: "商品管理",
                icon: <SmileOutlined />,
                element: <Outlet />,
                children: [
                    {
                        path: "/product",
                        label: "商品管理",
                        isHide: true,// 是否隐藏
                        element: <Navigate to={"/product/trademark"} />
                    },
                    {
                        // 品牌管理
                        path: "/product/trademark",
                        label: "品牌管理",
                        element: lazyLoading("product/trademark")
                    },
                    {
                        // 三级联动
                        path: "/product/category",
                        element: lazyLoading("product/category"),
                        label: "三级联动"
                    }
                ]
            }
        ]
    }, {
        path: "/login",
        element: lazyLoading("Login")
    }, {
        path: "*",
        element: lazyLoading("NotFound")
    }
];

// 响应路由配置
export default function () {
    // /cmn/dict
    return useRoutes(routes)
}
// 响应侧边栏
export const renderSlider = function () {
    return (routes.find(v => v.path === "/") as any).children;
}